package com.julu.o2o.config;

import org.beetl.core.GroupTemplate;
import org.beetl.ext.jfinal.BeetlRenderFactory;
import org.beetl.sql.ext.jfinal.JFinalBeetlSql;
import org.beetl.sql.ext.jfinal.Trans;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.Controller;
import com.jfinal.core.JFinal;
import com.jfinal.ext.route.AutoBindRoutes;
import com.jfinal.kit.PropKit;
import com.jfinal.render.ViewType;


public class SystemConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use("jfinal.properties");
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("jfinal.properties");
		me.setDevMode(getPropertyToBoolean("devMode", true));
		// Beetl
		me.setMainRenderFactory(new BeetlRenderFactory());		
		GroupTemplate gt = BeetlRenderFactory.groupTemplate;
		//根据gt可以添加扩展函数，格式化函数，共享变量等
		me.setViewType(ViewType.JSP);
		me.setEncoding("UTF-8");			
		
	}

	@Override
	@SuppressWarnings("unchecked")
	public void configRoute(Routes me) {
		AutoBindRoutes routes = new AutoBindRoutes();
		routes.addExcludeClasses(Controller.class);		
		me.add(routes);

	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		JFinalBeetlSql.init();
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		//me.add(new PowerInterceptor());
		me.addGlobalActionInterceptor(new Trans());
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

	/**
	 * 建议使用 JFinal 手册推荐的方式启动项目 运行此 main
	 * 方法可以启动项目，此main方法可以放置在任意的Class类定义中，不一定要放于此
	 */
	public static void main(String[] args) {
		JFinal.start("src/main/webapp", 80, "/", 5);
	}

}
